<?php
$CI =& get_instance();
$sBasePath = public_base_url().'js/fckeditor/' ;
$external_link = $CI->config->item('external_link');
$action = $CI->uri->segment(2);
?>
<script type="text/javascript">
function SetFileField(fileUrl) {
	$('#icon_img').val(fileUrl);
}
$(document).ready(function() {
	var finder = new CKFinder();
	finder.BasePath = '<?=base_url()?>system/plugins/ckfinder/';
	finder.SelectFunction = SetFileField;
	$("#icon_img_btn").bind("click", function(){
		finder.Popup();
	});
	$("#linkBtn").click(function(){
		$("#dialog").dialog({
			modal: true,
			autoOpen: false,
			height: 580,
			width: 650,
			title: 'Site Links',
			buttons: {
					Ok: function() {
						$(this).dialog('close');
					}
			}
		});
		$('#dialog').load("<?=site_url(array('c' => 'cms_home', 'm' => 'sitelink'))?>", function(){
			//$('#sitemap a').find("a").each(function(){});
			$('#sitemap a').click(function(){
				$("#targetLink").val($(this).attr("href"));
				$("#dialog").dialog("close");
				return false;
			});
		});
		$("#dialog").dialog("open");
		return false;
	});

});

function preview_content(action){
	if(action == 'edit'){
		$("#dialog").dialog({
			modal: true,
			autoOpen: false,
			height: 1000,
			width: 1000,
			title: 'Site Links',
			buttons: {
					Ok: function() {
						$(this).dialog('close');
					}
			}
		});
		$('#dialog').load("<?=site_url(array('c' => 'cmssiteframe', 'm' => 'preview_node'))?>", function(){
			$('#sitemap a').click(function(){
				$("#targetLink").val($(this).attr("href"));
				$("#dialog").dialog("close");
				return false;
			});
		});
		$("#dialog").dialog("open");
		return false;
	}
}

</script>
<table border="0" cellspacing="0" cellpadding="0" class="cont-table">
<tr>
	<th>Navigation Name:</th>
	<td><input type="text" name="item_nav_name" class="input-text" value="<?=$ed['nav_name']?>"></td>
	<th>Target:</th>
	<td nowrap="nowrap">
		<select name="item_target" class="input-text">
			<?php foreach($external_link as $key => $item) :?>
				<option value="<?=$item['val']?>" <?= $ed['target']==$item['val'] ? 'selected' : '';?>><?=$item['text']?></option>
			<?php endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>Title:</th>
	<td><input type="text" name="item_title" class="input-text" value="<?=$ed['title']?>"></td>
	<th>Target Link:</th>
	<td><input id="targetLink" name="item_target_link" type="text" class="input-text" value="<?=$ed['target_link']?>" /><input id="linkBtn" type="button" value="Links" name="storage"></td>
</tr>
<tr>
	<th>CSS Class</th>
	<td><input type="text" name="item_css_class" class="input-text" value="<?=$ed['css_class']?>"></td>
	<th><?php if(!empty($ed['icon'])):?>
		<img src="<?=$ed['icon']?>" style="vertical-align: middle;"/>
		<?php endif;?>
		Icon:</th>
	<td><input id="icon_img" name="item_icon" type="text" class="input-text" value="<?=$ed['icon']?>" /><input type="button" value="Browse" name="icon_img_btn" id="icon_img_btn"></td>
</tr>
<tr>
	<th>Banner</th>
	<td colspan="3">
		<?=$this->ckeditor->editor("item_banner", $ed['banner'], array("baseHref" => site_url()));?>
	</td>
</tr>
<tr>
	<th>Description:</th>
	<td colspan="3">
		<?=$this->ckeditor->editor("item_description", $ed['description'], array("baseHref" => site_url()));?>
	</td>
</tr>
<tr>
	<th>Keywords:</th>
	<td colspan="3">
		<textarea name="item_keyword" rows="7" class="input-textarea"><?=$ed['keyword']?></textarea>
	</td>
</tr>
<tr>
	<th>Inner Script:</th>
	<td colspan="3">
		<textarea name="item_inner_script" rows="7" class="input-textarea"><?=$ed['inner_script']?></textarea>
	</td>
</tr>
<tr>
	<th>Publish ?:</th>
	<td>
		<label>Yes</label><input type="radio" name="item_publish" value="1" <?php if($ed['publish']===null ||$ed['publish'] ) {echo 'checked';}?>/>
		<label>No</label><input type="radio" name="item_publish" value="0" <?php if(isset($ed['publish']) and ($ed['publish'] == 0) ) {echo 'checked';}?>/></td>
	<th>Access level:</th>
	<td>
		<select name="item_access_level" class="input-text">
			<option value="">Please select</option>
			<?php foreach($roles as $key => $item) :?>
				<option value="<?=$item['id']?>" <?= $ed['access_level']==$key ? 'selected' : '';?>><?=$item['name']?></option>
			<?php endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>Show in footer:</th>
	<td>
		<label>Yes</label><input type="radio" name="item_show_footer" value="1" <?php if($ed['show_footer']===null ||$ed['show_footer'] ) {echo 'checked';}?>/>
		<label>No</label><input type="radio" name="item_show_footer" value="0" <?php if(isset($ed['show_footer']) and ($ed['show_footer'] == 0) ) {echo 'checked';}?>/></td>
	</td>
	<th>Layout:</th>
	<td>
		<select name="item_layout" class="input-text">
			<option value="">Please Select</option>
			<?php foreach($layouts as $key => $item) :?>
				<option value="<?=$key?>" <?= $ed['layout']==$key ? 'selected' : '';?>><?=$item?></option>
			<?php endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>&nbsp;</th>
	<td colspan="3" class="space">
		<input type="hidden" name="item_level" value="<?=$ed['level']?>"/>
		<input type="hidden" name="item_pid" value="<?=$ed['pid']?>"/>
		<input type="hidden" name="flag" value="1"/>
		<input name="save" type="submit" class="ins" value="Save"/>
		<input name="preview" type="button" class="ins" value="Preview" onclick="preview_content('<?=$action?>')"/>
	</td>
</tr>
</table>